#include "bird.h"
#include "ui_bird.h"
#include<QPainter>
bird::bird(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::bird)
{
    ui->setupUi(this);
    this->setGeometry(QRect(600,300,500,300));
}

bird::~bird()
{
    delete ui;
}
void bird::paintEvent(QPaintEvent *event){
     QPainter painters(this);
     initwall();
     initbir();
     //游戏背景
     painters.setPen(Qt::black);//外
     painters.setBrush(Qt::blue);
     painters.drawRect(10,10,450,270);
     painters.setPen(Qt::black);//内
     painters.setBrush(Qt::black);
     painters.drawRect(25,25,420,240);
     //分格
     painters.setPen(Qt::white);
     for(int i = 25;i <= 265;i+=15){//横
         painters.drawLine(25,i,445,i);
     }
     for(int i = 25;i <= 445;i+=15){//竖
         painters.drawLine(i,25,i,265);
     }
     //画墙
     painters.setPen(Qt::green);
     painters.setBrush(Qt::green);
     painters.drawRect(vwallrect);
     //画鸟
     painters.setPen(Qt::red);
     painters.setBrush(Qt::red);
     painters.drawRect(vbirrect);
}
void bird::initwall(){
    QRect rectw(415,25,30,15);//一个墙的初始位置
    vwallrect=rectw;
    timer=new QTimer(this);//设计计时器
    timer.start(100);//每100ms触发一次：墙的移动速度
    connect(timer,signal(timeout()),SLOT(wall_update()));
}
void bird::initbir(){
    QRect rectb(175,115,15,15);//鸟初始位置及大小
    vbirrect=rectb;
}
void bird::wall_update(){

}
void bird::bir_update(){
    if(ndierc_bir==1){//鸟向上蹦
        vbirrect.setTop(vbirrect.top()-15);
    }
}
void bird::keyPressEvent(QKeyEvent *event){
    QKeyEvent *key=(QKeyEvent*) event;
    if(key->key()==Qt::Key_Space){
        ndierc_bir=1;
    }
}

























